package com.reddys.rrp.enrollment.util;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;

import com.reddys.rrp.enrollment.dao.StudentRegistrationDAO;
import com.reddys.rrp.enrollment.db.Course;
import com.reddys.rrp.enrollment.db.Student;

public class HibernateUtil {
	
	SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
	
	Session session = null;
	
	public HibernateUtil(){
		session = sf.openSession();
	}

	public Session getSession() {
		return session;
	}

	public static void save(Object obj){
		HibernateUtil util = new HibernateUtil();
		Session session = util.getSession();
		Transaction tx = session.beginTransaction();
		tx.begin();
		session.save(obj);
		tx.commit();
		
	}
	
	public static void main(String args[]){
		Course course = new Course();
		course.setCourseName("Struts");
		course.setCourseDesc("sdhshh");
		Course course1 = new Course();
		course1.setCourseName("hibernate");
		course1.setCourseDesc("sdhshh");
		Course course2 = new Course();
		course2.setCourseName("JSF");
		course2.setCourseDesc("sdhshh");


		HibernateUtil.save(course);
		HibernateUtil.save(course1);
		HibernateUtil.save(course2);
	}
}
